home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_gen / euphor14.zip / EPRINT.EX < prev    next >
Text File  |  1996-10-15  |  5KB  |  191 lines

  1.         ------------------------------
  2.         -- Print a Euphoria program --
  3.         ------------------------------
  4. -- This works with HP PCL printers.
  5. -- You can change control codes (bold, italics etc) for other printers.
  6. -- If you have a color printer you can choose colors,
  7. -- otherwise you will simply get keywords in bold, comments in italics.
  8. -- You can print non-Euphoria files too.
  9.  
  10. -- usage: eprint filename
  11.  
  12.  
  13. constant TRUE = 1, FALSE = 0
  14. constant ERROR = 2
  15.  
  16. ---- some parameters you can adjust for your printer --------------------------
  17. constant NCOLUMNS = 2              -- 1 or 2
  18. constant CONDENSED = TRUE          -- TRUE or FALSE
  19. constant PAGE_LENGTH = 59*NCOLUMNS -- (upper bound) 118 for condensed
  20. constant COLOR_PRINTER = FALSE     -- TRUE (HP550C) or FALSE
  21. integer syntax
  22. syntax = TRUE                      -- to highlight syntax in .e/.ex/.pro files
  23. -------------------------------------------------------------------------------
  24.  
  25. constant ESC = 27
  26.  
  27. constant hp550c = {"2", "8", "1", "12", "4", "10", "1", "1"}
  28.  
  29. integer printer
  30.  
  31. procedure bold_on()
  32.     puts(printer, ESC & "(s3B")
  33. end procedure
  34.  
  35. procedure bold_off()
  36.     puts(printer, ESC & "(s0B")
  37. end procedure
  38.  
  39. procedure italics_on()
  40.     puts(printer, ESC & "(s1S")
  41. end procedure
  42.  
  43. procedure italics_off()
  44.     puts(printer, ESC & "(s0S")
  45. end procedure
  46.  
  47. procedure second_column()
  48.     puts(printer, ESC & "&a80C")
  49. end procedure
  50.  
  51. procedure form_feed()
  52.     puts(printer, 12)
  53. end procedure
  54.  
  55. procedure reset()
  56.     puts(printer, ESC & 'E')   -- reset
  57. end procedure
  58.  
  59. procedure color()
  60.     puts(printer, ESC & "*r-4U")  -- CYMK
  61. end procedure
  62.  
  63. procedure small()
  64.     puts(printer, ESC & "(s20H")    -- Print Pitch (width)
  65.     puts(printer, ESC & "(s8V")     -- Point Size (height)
  66.     puts(printer, ESC & "&l4C")     -- vertical motion
  67. end procedure
  68.  
  69. -- symbols needed by syncolor.e:
  70. global integer SCREEN
  71. global constant  NORMAL_COLOR = 8,
  72.         COMMENT_COLOR = 4,
  73.         KEYWORD_COLOR = 1,
  74.         BUILTIN_COLOR = 5,
  75.          STRING_COLOR = 6
  76.  
  77. global constant BRACKET_COLOR = {NORMAL_COLOR}
  78.  
  79. global procedure text_color(integer color)
  80. -- this overrides the graphics.e procedure for screen color
  81. -- that is used by syncolor.e
  82.     sequence color_code
  83.  
  84.     if not syntax then
  85.     return
  86.     end if
  87.  
  88.     if COLOR_PRINTER then
  89.     color_code = hp550c[color]
  90.     puts(printer, ESC & "*v" & color_code & "S")
  91.     else
  92.     -- normal mono printer
  93.     if color = KEYWORD_COLOR then
  94.         italics_off()
  95.         bold_on()
  96.     elsif color = COMMENT_COLOR then
  97.         bold_off()
  98.         italics_on()
  99.     else
  100.         italics_off()
  101.         bold_off()
  102.     end if
  103.     end if
  104. end procedure
  105.  
  106. include syncolor.e
  107.  
  108. procedure try_colors()
  109. -- display colors on hp550c
  110.     for i = '0' to '6' do
  111.     for j = '0' to '9' do
  112.         puts(printer, ESC & "*v" & i & j & "S")
  113.         printf(printer, "%s:", {i&j})
  114.         puts(printer, "Testing Colors ...\n")
  115.     end for
  116.     end for
  117. end procedure
  118.  
  119. procedure eprint()
  120.     integer efile
  121.     sequence command, matchname
  122.     object line
  123.     sequence buffer
  124.     integer base_line
  125.  
  126.     command = command_line()
  127.     if length(command) != 3 then
  128.     puts(ERROR, "usage: eprint filename\n")
  129.     return
  130.     end if
  131.     efile = open(command[3], "r")
  132.     if efile = -1 then
  133.     puts(ERROR, "couldn't open " & command[3] & '\n')
  134.     return
  135.     end if
  136.     matchname = command[3] & '&'
  137.     if not match(".e&", matchname) and
  138.        not match(".ex&", matchname) and
  139.        not match(".pro&", matchname) then
  140.     syntax = FALSE
  141.     end if
  142.     printer = open("PRN", "w")
  143.     if printer = -1 then
  144.     puts(ERROR, "Can't open printer\n")
  145.     return
  146.     end if
  147.     SCREEN = printer -- SCREEN is needed by syncolor
  148.     init_class()
  149.     reset()
  150.     if COLOR_PRINTER then
  151.     color()
  152.     end if
  153.     if CONDENSED then
  154.     small()
  155.     end if
  156.  
  157.     -- read in whole file
  158.     buffer = {}
  159.     while TRUE do
  160.     line = gets(efile)
  161.     if atom(line) then
  162.         exit
  163.     end if
  164.     if line[length(line)] != '\n' then
  165.         line = line & '\n' -- need end marker
  166.     end if
  167.     buffer = append(buffer, line)
  168.     end while
  169.     base_line = 1
  170.     while base_line <= length(buffer) do
  171.     for i = base_line to base_line + PAGE_LENGTH - 1 do
  172.         if i <= length(buffer) then
  173.         DisplayColorLine(buffer[i])
  174.         if NCOLUMNS = 2 and i + PAGE_LENGTH <= length(buffer) then
  175.             second_column()
  176.             DisplayColorLine(buffer[i + PAGE_LENGTH])
  177.         end if
  178.         puts(printer, '\n')
  179.         end if
  180.     end for
  181.     base_line = base_line + PAGE_LENGTH * NCOLUMNS
  182.     form_feed()
  183.     end while
  184.     close(efile)
  185.     reset()
  186.     close(printer)
  187. end procedure
  188.  
  189. eprint()
  190.  
  191.